<!-- 添加求职期望 -->
<template>
	<view>
		<view class="page">
			<u-form :model="form" ref="uForm">
				<u-form-item label="公司">
					<u-input v-model="form.companyName" placeholder="输入工作公司" />
				</u-form-item>
				<u-form-item label="岗位">
					<u-input v-model="form.jobName" placeholder="输入从事岗位" />
				</u-form-item>
				<u-form-item label="内容">
					<u-input v-model="form.content" placeholder="输入工作内容" type="textarea" />
				</u-form-item>
				<u-form-item label="时间">
					<view class="picker">
						<view class="pickeritem flex justify-between">
							<picker mode="date" :value="stdt" :start="start" @change="bindDateChange1">{{stdt}}</picker>
							-
							<picker mode="date" :value="eddt" :end="end" @change="bindDateChange2">{{eddt}}</picker>
						</view>
					</view>
				</u-form-item>
			</u-form>

		</view>
		<view class="button flex justify-center align-center" @click="submit">提 交</view>
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				form: {
					companyName: '',
					content: '',
					jobName: '',
					startDat: '',
					endDate: ''
				},
				stdt: currentDate,
				eddt: currentDate,
				start: '',
				end: '',
			}
		},
		computed: {
			start() {
				return this.getDate('start');
			},
			end() {
				return this.getDate('end');
			}
		},
		methods: {
			async submit() {
				this.form.startDate = this.stdt
				this.form.endDate = this.eddt
				await this.$post('/userResumeWorkExperience/save', this.form)
				await uni.navigateBack({
					delta: 1
				})
			},
			bindDateChange1(e) {
				this.stdt = e.target.value
			},
			bindDateChange2(e) {
				this.eddt = e.target.value
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				let hour = date.getHours();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
		}
	}
</script>

<style lang="scss">
	.page {
		padding: 20rpx;
	}

	.button{
		position: fixed;
		bottom: calc(20rpx + env(safe-area-inset-bottom));
		width: 690rpx;
		left:30rpx;
		height: 75rpx;
		background: #0265EB;
		border-radius: 38rpx;
		line-height: 75rpx;
		font-weight: 500;
		color: #FFFFFF;
		font-size: 32rpx;
		box-shadow: 0rpx 10rpx 10rpx rgba(12,108,240, .4);
	}
</style>
